﻿using NHibernate.Validator.Constraints;
using TestBat.IModels.Domain;

namespace TestBat.Models.Domain
{
    public class TestChoice : DomainEntity, ITestChoice
    {
        [NotNull]
        public virtual bool Correct
        {
            get;
            set;
        }

        [NotNullNotEmpty]
        [Length(255)]
        public virtual string Text
        {
            get;
            set;
        }

        [NotNull]
        public virtual ITestChoiceTask Task
        {
            get { return task; }
            set
            {
                if (Equals(task, value))
                    return; // no change needed

                if (task != null)
                    task.Choices.Remove(this); // remove from old task

                task = value;

                if (task != null)
                    task.Choices.Add(this); // add to new task's children
            }
        }

        private ITestChoiceTask task;
    }
}
